home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / emmpas.zip / EMSDEMO.PAS < prev   
Pascal/Delphi Source File  |  1993-01-04  |  6KB  |  160 lines

  1. {$O+,F+} { Allow Overlays                   }
  2. {$R-}    { No range checking                }
  3. {$S-}    { No stack checking                }
  4. {$I-}    { No I/O checking                  }
  5. {$V-}    { No string checking               }
  6. {$B-}    { Boolean short circuit evaluation }
  7. {$N-}    { No numeric coprocessor           }
  8. {$D-}    { No debug information             }
  9. {$M 1024, 0, 4096}
  10.  
  11. (*┌───────────────────────────────────────────────────────────────────────────┐
  12.   │ AstroSoft Data Systems LIM EMS 3.2 Unit demo program.                     │
  13.   │ This program shows you how to use the ASEMS unit to dynamically allocate a│
  14.   │ structure larger than the 64K page frame.  The program allocates 8 16K    │
  15.   │ pages of EMS memory 3.2 or above and then initializes an array of 80      │
  16.   │ character strings 1618 long writes them to the screen and then releases   │
  17.   │ the associated handle.  It is quite easy to allocate and use EMS memory   │
  18.   │ with this unit if the allocated structures have a constant record size.   │
  19.   │ It would be quite some work to get the structures to switch with variable │
  20.   │ length records.  It is important to release the handles in your program   │
  21.   │ under terminations other than normal ones.  If handles are left in        │
  22.   │ memory they should not hazard the system, it is just sloppy practice.     │
  23.   └───────────────────────────────────────────────────────────────────────────┘*)
  24.  
  25. (* Direct questions or comments to AstroSoft Data Systems PO Box 12295, *)
  26. (*                                 Baltimore, Maryland 21224            *)
  27. (*                                 301-276-6569                         *)
  28.  
  29. PROGRAM Test1;                  { Program Name }
  30.  
  31. USES CRT, ASEMS;                { Need to put ASEMS in USES clause }
  32.  
  33. TYPE
  34. Str55     =   STRING [ 55 ];    { Program types }
  35. Str3      =   STRING [ 03 ];
  36. Str4      =   STRING [ 04 ];
  37. Str8      =   STRING [ 08 ];
  38. Str80     =   STRING [ 80 ];
  39. Str80Ptr  =   ^Str80;
  40.  
  41. VAR
  42.  
  43. Handle,                         { LIM EMS handle }
  44. Address,                        { Base address of EMS physical page frame }
  45. I, J        : WORD;             { Loop counter variables }
  46. Error       : Str55;            { Error string passed to the program }
  47. Version     : Str3;             { EMS version string }
  48. Ch          : CHAR;             { stop key character }
  49. BasePtr     : POINTER;          { Pointer to base of array within page frame }
  50. TestArray   : ARRAY [ 1..809 ] OF Str80Ptr;  { array of string pointers }
  51. NumString   : Str4;             { Used for number string }
  52. Number      : WORD;             { Word variable used to pass number of handles }
  53.  
  54.  
  55. {$F+} PROCEDURE CustomExit; {$F-}
  56. BEGIN
  57.   IF NOT ReleaseHandle ( Handle, Error ) THEN
  58.   WRITELN ( 'Handles not released : ', Error );
  59. END;
  60.  
  61. BEGIN
  62.  
  63. ExitProc       := @CustomExit;   { Release handles during terminations other }
  64. CHECKBREAK     := TRUE;         { than normal. ie Interrupt 20h             }
  65. TEXTBACKGROUND ( BLUE );
  66. TEXTCOLOR      ( LIGHTCYAN );
  67. CLRSCR;
  68.  
  69. IF NOT MapAndTestPages ( 8, 0, 1, 2, 3, Handle, Address, Error ) THEN
  70.  
  71. WRITELN  ( Error )         { If not successful then write cause of error }
  72. ELSE
  73. BEGIN                      { If successful then fill the array of pointers }
  74.                            { with addresses starting at the base of the    }
  75.                            { page frame                                    }
  76.  
  77. IF HandleCount ( Number, Error ) THEN   { Get the number of handles in use }
  78. WRITELN  ( 'Number of handles in use: ', Number ) { Write the number      }
  79. ELSE
  80. WRITELN  ( Error );    { If unsuccessful then write the cause of the error }
  81. WRITELN;
  82. IF HandlePages ( Handle, Number, Error ) THEN  { Get the number of handles }
  83.                                                { currently used by application }
  84. WRITELN ( 'Number of pages in use for present handle : ', Number )
  85. ELSE
  86. WRITELN ( Error );                  { If unsuccessful the write the cause }
  87. WRITELN;
  88.  
  89. { Write the address of the base of the physical page frame }
  90.  
  91. WRITELN  ( 'EMM Base Page Frame Address: ', HexString ( Address ) );
  92. IF ( EMMVersion ( Version ) = 0 ) THEN
  93.  
  94. { Write the EMM version }
  95.  
  96. WRITELN  ( 'EMM Driver Version         : ', Version   );
  97. WRITELN;
  98. IF GetMappingSize ( Number, Error ) THEN
  99. WRITE ( 'Number of bytes to save mapping array: ', Number );
  100. WRITELN;
  101. WRITELN;
  102. WRITELN  ( 'Mapping and Allocation completed without error' );
  103. WRITELN;
  104. WRITELN  ( 'Strike any key to read strings to (2) 64 Kb page maps ...' );
  105. Ch := READKEY;                       { Wait for a key stroke }
  106.  
  107. FOR I := 1 TO 809 DO
  108. TestArray [ I ] :=  PTR ( Address , ( I * 81 ) - 81 );
  109.  
  110.  
  111. FOR I := 1 TO 809 DO        { Fill the array in the first page map }
  112. BEGIN
  113. STR ( I, NumString );
  114. TestArray [ I ]^ := 'Testing Array Position #' + Numstring;
  115. END;
  116.  
  117. WRITELN;
  118. WRITELN  ( 'Strike any key to read strings from EMS to the screen ...' );
  119. Ch := READKEY;
  120.  
  121. FOR I := 1 TO 809 DO             { Write the array to the screen }
  122. WRITELN ( TestArray [ I ]^ );
  123. WRITELN;
  124. WRITELN ( 'Remapping to second page frame : Strike any key ...' );
  125. Ch := Readkey;
  126. { Remap to the second four pages allocated }
  127. IF NOT Remap ( 4, 5, 6, 7, Handle, Error ) THEN
  128. WRITELN ( Error )
  129. ELSE
  130.   BEGIN
  131.   FOR I := 1 TO 809 DO       { Store and write the second page mapped array }
  132.   BEGIN
  133.   STR ( I + 809, NumString );
  134.   TestArray [ I ]^ := 'Testing Array Position #' + Numstring;
  135.   END;
  136.   FOR I := 1 TO 809 DO
  137.   BEGIN
  138.   WRITELN ( TestArray [ I ]^ );
  139.   END;
  140.   END;
  141. END;
  142. WRITELN;
  143. WRITELN ( 'Restoring to first page frame : Strike any key ...' );
  144. Ch := Readkey;
  145. { Restore to the first page map }
  146. IF NOT Remap ( 0, 1, 2, 3, Handle, Error ) THEN
  147. WRITELN ( Error );
  148.  
  149. { Write out values from the first half of the 128K array }
  150. FOR I := 1 TO 809 DO WRITELN ( TestArray [ I ]^ );
  151. WRITELN;
  152.  
  153. WRITELN ( 'Strike any key to deallocate the EMS handle ...' );
  154. Ch := Readkey;
  155. { Release the handle in use for other applications }
  156. IF NOT ReleaseHandle ( Handle, Error ) THEN WRITELN ( Error );
  157. CLRSCR;
  158.  
  159. END.
  160.